#include<vector>
#include<algorithm>
using namespace std;

class Solution {
public:
    int eraseOverlapIntervals(vector<vector<int>>& intervals) {
        if (intervals.size() <= 1)return 0;
        sort(intervals.begin(), intervals.end(), [](const vector<int>& left, const vector<int>& right) {
            return left[1] < right[1];
            });
        int end = intervals[0][1];
        int ans = 0;
        for (int i = 1; i < intervals.size(); ++i) {
            if (end > intervals[i][0]) 
                ++ans;
            else 
                end = intervals[i][1];
        }
        return ans;
    }
};